/*****************************************************************************
 *
 *                      HUSONG PROPRIETARY INFORMATION
 *
 *          The information contained herein is proprietary to HUSONG
 *           and shall not be reproduced or disclosed in whole or in part
 *                    or used for any design or manufacture
 *              without direct written authorization from HUSONG.
 *
 *            Copyright (c) 2015 by HUSONG.  All rights reserved.
 *
 *****************************************************************************/
package me.send.business.service.mapper;

import java.util.List;
import java.util.Map;

import me.send.business.service.pojo.Message;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

/**
 * @author maxmin
 *
 * @date 2015年8月25日 下午2:07:54
 */
public interface MessageMapper {

	/**
	 * 添加消息记录
	 * 
	 * @param message
	 * @return
	 */
	@Insert(value = "INSERT INTO message (message,user_id,user_type,type,orderid,from_user_id,createtime,updatetime) "
			+ "values (#{message},#{userId},#{userType},#{type},#{orderId},#{fromUserId},#{createtime},#{updatetime})")
	public int addMessage(Message message);

	/**
	 * 获取消息列表
	 * 
	 * @param params
	 * @return
	 * @author maxmin
	 * @date 2015年8月31日下午4:54:37
	 */
	@Select(value = "SELECT DISTINCT m.message_id messageId,m.message,m.createtime,m.type,m.orderid FROM message m "
			+ "WHERE m.user_id=#{userid} AND m.user_type= 1 AND IF(#{type}=1,m.type=#{type},m.type>=#{type}) AND "
			+ "IF (#{startid}>0,m.message_id<#{startid},1=1) "
			+ "ORDER BY m.message_id DESC Limit #{size}")
	public List<Message> getMessages(Map<String, Object> params);
}
